﻿using System;
using System.Linq;
using System.Threading.Tasks;
using YXChatApiService.Core.Common;
using YXChatApiService.Repository;

namespace YXChatApiService.Core.AccountEntity.DomainManager
{
    public class AccountManager:DomainBaseManager<Account,Guid>,IAccountManager
    {
        public AccountManager(IRepository<Account, Guid> repository) : base(repository)
        {
        }
        public async Task<Account> InsertAsync(Account entity)
        {
            return await Repo.InsertAsync(entity);
        }

        public async Task DeleteAsync(Guid id)
        {
            var entity = await Repo.FirstOrDefaultAsync(n => n.Id==id);
            await Repo.DeleteAsync(entity);
        }

        public async Task<Account> UpdateAsync(Account entity)
        {
            return await Repo.UpdateAsync(entity);
        }

        public Account GetAccount(string accountNumber)
        {
            return Repo.FirstOrDefault(n => n.AccountNumber == accountNumber);
        }

        public Account Get(Guid id)
        {
            return Repo.FirstOrDefault(n => n.Id == id);
        }
    }
}